package Year21_Month12.day1205;

public class Soultion1 {
    //删除字符串中相邻的重复元素
    public static String removeDuplicates(String s) {
        int i = -1;
        int j =  0;
        char[] arr = s.toCharArray();
        while(j < arr.length){
            if(i >= 0 && arr[i] == arr[j]){
                i--;
            }else{
                i++;
                arr[i] = arr[j];
            }
            j++;
        }
        return String.copyValueOf(arr,0,i+1);
    }

    public static void main(String[] args) {
        String s = "abbaca";
        System.out.println(removeDuplicates(s));
    }
}
